using System.Collections;
using Framework;
using UnityEngine;

public abstract class ActorBase : EntityLogic
{
    public bool Enabled { get; protected set; }
    private CoroutineID _id;
    protected override void OnStart()
    {
        base.OnStart();
        Enabled = true;
        GameEntry.Context.World.MapGrid.Add(this);
    }
    protected override void OnDestroy()
    {
        base.OnDestroy();
        GameEntry.Context.World.MapGrid.Remove(this);
        GameEntry.Coroutine.Stop(_id);
        _id = null;
    }
    public virtual ActorType GetActorType()
    {
        return ActorType.Unknow;
    }

    public virtual Vector3 GetWorldPosition()
    {
        return GameObject.transform.position;
    }
    public void Ping()
    {
        if (GameObject == null) return;
        _id = GameEntry.Coroutine.Start(ping());
    }
    IEnumerator ping()
    {
        Vector3 add = new Vector3(0.1f, 0.1f, 0.1f);
        int count = 10;
        while (count-- > 0)
        {
            GameObject.transform.localScale += add;
            yield return null;
        }
        count = 10;
        while (count-- > 0)
        {
            GameObject.transform.localScale -= add;
            yield return null;
        }
        _id = null;
    }
}